package grouplife::Schema::Result::User;

# Created by DBIx::Class::Schema::Loader
# DO NOT MODIFY THE FIRST PART OF THIS FILE

use strict;
use warnings;

use Moose;
use MooseX::NonMoose;
use namespace::autoclean;
extends 'DBIx::Class::Core';

__PACKAGE__->load_components(qw( TimeStamp Core EncodedColumn));
=head1 NAME

grouplife::Schema::Result::User

=cut

__PACKAGE__->table("users");

=head1 ACCESSORS

=head2 id

  data_type: 'integer'
  is_nullable: 0

=head2 username

  data_type: 'text'
  is_nullable: 1

=head2 password

  data_type: 'text'
  is_nullable: 1

=head2 email_address

  data_type: 'text'
  is_nullable: 1

=head2 first_name

  data_type: 'text'
  is_nullable: 1

=head2 photo

  data_type: 'text'
  is_nullable: 1

=head2 last_name

  data_type: 'text'
  is_nullable: 1

=head2 active

  data_type: 'integer'
  is_nullable: 1

=cut

__PACKAGE__->add_columns(
		"id",
		{ data_type => "integer", is_nullable => 0 },
		"username",
		{ data_type => "text", is_nullable => 1 },
		"password",
		{ data_type => "text", is_nullable => 1 },
		"created",
                { data_type => 'datetime', timezone => "Asia/Shanghai", set_on_create => 1 },
                "updated",
                { data_type => 'datetime', timezone => "Asia/Shanghai", set_on_create => 1, set_on_update => 1 },
		"email_address",
		{ data_type => "text", is_nullable => 1 },
		"full_name",
		{ data_type => "text", is_nullable => 1 },
		"comm_item_id",
		{ data_type => "integer", is_nullable => 1 },
		"university_id",
		{ data_type => "integer", is_nullable => 0 },
		"office_id",
		{ data_type => "integer", is_nullable => 0 },
		"house_id",
		{ data_type => "integer", is_nullable => 0 },
		"photo",
		{ data_type => "text", is_nullable => 1 },
		"active",
		{ data_type => "text", is_nullable => 1 },
);
__PACKAGE__->set_primary_key("id");


# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-03-28 04:13:18
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:H7gVAIRlqCdXnqER0UzV8A
__PACKAGE__->add_columns(
		'password' => {
		encode_column       => 1,
		encode_class        => 'Digest',
		encode_args         => {salt_length => 10},
		encode_check_method => 'check_password',
		},
		);

__PACKAGE__->has_many(
		"user_stores",
		"grouplife::Schema::Result::UserStore",
		{ "foreign.user_id" => "self.id" },
		);
__PACKAGE__->has_many(
		"user_stores_own",
		"grouplife::Schema::Result::UserStore",
		{ "foreign.user_id" => "self.id" },
		{where => {'role' => 'C' }},
		);

__PACKAGE__->has_many(
		"user_tuan",
		"grouplife::Schema::Result::UserTuan",
		{ "foreign.user_id" => "self.id" },
		);
__PACKAGE__->has_many(
		"tuans_created_by_me",
		"grouplife::Schema::Result::UserTuan",
		{ "foreign.user_id" => "self.id" },
		{where => {'role' => 'C' }},
		);
__PACKAGE__->has_many(
		"tuans_joined_by_me",
		"grouplife::Schema::Result::UserTuan",
		{ "foreign.user_id" => "self.id" },
		{where => {'role' => 'J' }},
		);
__PACKAGE__->has_many(
		"users_users",
		"grouplife::Schema::Result::UserUser",
		{ "foreign.friend_id" => "self.id" },
		);
__PACKAGE__->has_many(
		"users_friends",
		"grouplife::Schema::Result::UserUser",
		{ "foreign.me_id" => "self.id"},
		{where => {'status' => 'Y' }},
		);
__PACKAGE__->has_many(
		"my_requests",
		"grouplife::Schema::Result::UserUser",
		{ "foreign.me_id" => "self.id"},
		{where => {status => 'R'} },
		);
__PACKAGE__->has_many(
		"my_approves",
		"grouplife::Schema::Result::UserUser",
		{ "foreign.me_id" => "self.id"},
		{where => {status => 'A'} },
		);
__PACKAGE__->has_many(
		"my_news",
		"grouplife::Schema::Result::Mynew",
		{ "foreign.user_id" => "self.id" },
		);
__PACKAGE__->has_many(
                "comments",
                "grouplife::Schema::Result::Comment",
                { "foreign.user_id" => "self.id" },
                );
__PACKAGE__->has_many(
                "source_nick",
                "grouplife::Schema::Result::SourceNick",
                { "foreign.user_id" => "self.id" },
                );
__PACKAGE__->has_many(
                "user_tuan_stores",
                "grouplife::Schema::Result::UserTuanStore",
                { "foreign.user_id" => "self.id" },
                );
__PACKAGE__->might_have(
                "upd_topic",
                "grouplife::Schema::Result::Topic",
                { "foreign.lupd_user_id" => "self.id" },
                );
__PACKAGE__->might_have(
                "role",
                "grouplife::Schema::Result::Role",
                { "foreign.user_id" => "self.id" },
                );
__PACKAGE__->has_one(
                "university",
                "grouplife::Schema::Result::University",
                { "foreign.id" => "self.university_id" },
                );
__PACKAGE__->has_one(
                "office",
                "grouplife::Schema::Result::University",
                { "foreign.id" => "self.office_id" },
                );
__PACKAGE__->has_one(
                "house",
                "grouplife::Schema::Result::University",
                { "foreign.id" => "self.house_id" },
                );

__PACKAGE__->many_to_many(tuan => 'user_tuan', 'tuan');
__PACKAGE__->many_to_many(stores => 'user_stores', 'stores');
__PACKAGE__->many_to_many(own_stores => 'user_stores_own', 'stores');
__PACKAGE__->many_to_many(friends => 'users_friends', 'users');
__PACKAGE__->many_to_many(my_created_tuans => 'tuans_created_by_me', 'tuan');
__PACKAGE__->many_to_many(my_joining_tuans => 'tuans_joined_by_me', 'tuan');
__PACKAGE__->many_to_many(friends_requests => 'my_requests', 'users');
__PACKAGE__->many_to_many(friends_approves => 'my_approves', 'users');


# You can replace this text with custom code or comments, and it will be preserved on regeneration
__PACKAGE__->meta->make_immutable;
1;
